package patrol.mobile.com.mobilepatrol.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.TextView;
import android.widget.Toast;

import patrol.mobile.com.mobilepatrol.R;


/**
 * Created by Jan on 2014/6/23.
 */
public class MyToast extends Toast{
    private final static Object obj=new Object();
    private static MyToast instance;
    private TextView textView;

    public MyToast(Context context) {
        super(context);
        textView= (TextView) LayoutInflater.from(context).inflate(R.layout.toast_view_layout,null);
        setView(textView);
    }
    public MyToast(Context context, String str) {
        super(context);
        setText(str);
    }
    public MyToast(Context context, int resId) {
        super(context);
        setText(resId);
    }

    @Override
    public void setText(int resId) {
        textView.setText(resId);
    }

    @Override
    public void setText(CharSequence s) {
        textView.setText(s);
    }

    public static MyToast makeText(Context context,String msg,int duration){
        synchronized (obj) {
            if (instance == null) {
                instance = new MyToast(context);
            }
            instance.setText(msg);
            instance.setDuration(duration);
        }

        return instance;
    }

    public static MyToast makeText(Context context,int resId,int duration){

        return makeText(context,context.getString(resId),duration);
    }
}
